package 并发编程12.同步屏障;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @author idea
 * @data 2019/2/24
 */
class Waiting implements Runnable{

    private CyclicBarrier cyclicBarrier;

    public Waiting(CyclicBarrier cyclicBarrier){
        this.cyclicBarrier=cyclicBarrier;
    }

    @Override
    public void run() {
        try {
            System.out.println("await!");
            cyclicBarrier.await();
            System.out.println("执行----");
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class Demo {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier=new CyclicBarrier(5);
        for(int i=0;i<10;i++){
            Thread t=new Thread(new Waiting(cyclicBarrier));
            t.start();
        }

    }
}
